package com.example.sharesinfo.utils;

import android.graphics.Color;
import android.widget.TextView;

import java.util.List;
import java.util.regex.Pattern;

public class CommonUtils {

    /**
     * 检查List是否可用
     *
     * @param list
     * @return
     */
    public static boolean isEmpty(List list) {
        return list != null && list.size() > 0;
    }

    /**
     * 判断字符是否为正整数
     * 为正整数返回true
     */
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    public static void setTextColor(TextView textView, String str) {
        str = str.replace("万", "").replace("亿", "").replace("%", "");
        try {
            Float number = Float.valueOf(str);
            if (number >= 0) {
                textView.setTextColor(0xFFED382B);
            } else {
                textView.setTextColor(0xFF169619);
            }
        } catch (Exception e) {
            LogUtils.i("");
        }

    }
}